package com.wenlin.myproduction.ui;

import android.os.Bundle;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.wenlin.myproduction.R;
import com.wenlin.myproduction.base.BaseActivity;
import com.wenlin.myproduction.bean.ProductBean;
import com.wenlin.myproduction.bean.TitleBean;
import com.wenlin.myproduction.binder.ProductBinder;
import com.wenlin.myproduction.binder.TitleBinder;
import com.wenlin.myproduction.util.MyGridLayoutManager;
import com.wenlin.myproduction.util.ValCommon;

import butterknife.BindView;
import me.drakeet.multitype.Items;
import me.drakeet.multitype.MultiTypeAdapter;

public class MainActivity extends BaseActivity {
    @BindView(R.id.rv)
    RecyclerView rv;

    private MultiTypeAdapter adapter;
    private Items items = new Items();

    @Override
    public int getContentView() {
        return R.layout.activity_main;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        adapter = new MultiTypeAdapter(items);
        adapter.register(ProductBean.class, new ProductBinder());
        adapter.register(TitleBean.class, new TitleBinder());
        MyGridLayoutManager manager = new MyGridLayoutManager(this, 3);
        manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                return items.get(position) instanceof TitleBean ? 3 : 1;
            }
        });
        rv.setLayoutManager(manager);
        rv.setAdapter(adapter);
        rv.setHasFixedSize(true);
        setData();
    }

    private void setData() {
        items.add(new TitleBean("自定义控件"));
        items.add(new ProductBean(ValCommon.BANNER_VIEW, v -> BannerViewActivity.start(this)));
        items.add(new ProductBean(ValCommon.CHART_VIEW, v -> ChartViewActivity.start(this)));
        items.add(new ProductBean(ValCommon.GOLD_VIEW, v -> GoldViewActivity.start(this)));
        items.add(new ProductBean(ValCommon.HISTOGRAM_VIEW, v -> HistogramViewActivity.start(this)));
        items.add(new ProductBean(ValCommon.INFO_ANIM_VIEW, v -> InfoAnimViewActivity.start(this)));
        items.add(new ProductBean(ValCommon.LOGO_ANIM_VIEW, v -> LogoAnimViewActivity.start(this)));
        items.add(new ProductBean(ValCommon.MARQUEE_VIEW, v -> MarqueeViewActivity.start(this)));
        items.add(new ProductBean(ValCommon.NUMBER_VIEW, v -> NumberViewActivity.start(this)));
        items.add(new ProductBean(ValCommon.PIC_PROGRESS_VIEW, v -> PicProgressViewActivity.start(this)));
        items.add(new ProductBean(ValCommon.LINE_PROGRESS_BAR, v -> LineProgressActivity.start(this)));
        items.add(new ProductBean(ValCommon.ROUND_CIRCLE_GRADIENT_PROGRESS, v -> RoundCircleGradientProgressActivity.start(this)));
        items.add(new ProductBean(ValCommon.ROUND_BANNER, v -> RoundBannerActivity.start(this)));
        items.add(new ProductBean(ValCommon.PIC_VIDEO_BANNER, v -> PicVideoBannerActivity.start(this)));
        items.add(new ProductBean(ValCommon.TIME_VIEW, v -> TimeViewActivity.start(this)));
        items.add(new ProductBean(ValCommon.TIME_PERCENT, v -> TimePercentActivity.start(this)));
        items.add(new ProductBean(ValCommon.CIRCLE_LIGHT, v -> CircleLightActivity.start(this)));
        items.add(new ProductBean(ValCommon.LABELS_VIEW, v -> LabelsViewActivity.start(this)));
        items.add(new ProductBean(ValCommon.MOSAIC_VIEW, v -> MosaicViewActivity.start(this)));

        items.add(new TitleBean("游戏"));
        items.add(new ProductBean(ValCommon.LOTTERY_CIRCLE_VIEW, v -> LotteryCircleViewActivity.start(this)));
        items.add(new ProductBean(ValCommon.BOOM_VIEW, v -> BombViewActivity.start(this)));
        items.add(new ProductBean(ValCommon.SHU_DU_VIEW, v -> ShuDuActivity2.start(this)));
        items.add(new ProductBean(ValCommon.FLIP_CARD_GAME, v -> FlipCardActivity.start(this)));
        items.add(new ProductBean(ValCommon.GUESS_NUMBER_GAME, v -> GuessNumberActivity.start(this)));
        items.add(new ProductBean(ValCommon.GET_24_POINTS_GAME, v -> Get24PointsActivity.start(this)));

        items.add(new TitleBean("其他项目"));
        items.add(new ProductBean(ValCommon.IN_OUT_RECORDS, v -> InOutActivity.start(this)));
        items.add(new ProductBean(ValCommon.GUESS_NUMBER_MAGIC, v -> GuessNumberMagicActivity.start(this)));
        items.add(new ProductBean(ValCommon.PLAYER_MATCH, v -> PlayerMatchActivity.start(this)));
        items.add(new ProductBean(ValCommon.SCHEDULE_MANAGE, v -> ScheduleManageActivity.start(this)));
        items.add(new ProductBean(ValCommon.FRONT_AND_BACK_VIEW, v -> FrontAndBackViewActivity.start(this)));
        items.add(new ProductBean(ValCommon.E_SPORTS_MANAGER_CALCULATOR, v -> ESportsManagerRecruitmentCalculatorActivity.start(this)));
        items.add(new ProductBean(ValCommon.PK_LAYOUT, v -> PKLayoutActivity.start(this)));

        adapter.notifyDataSetChanged();
    }
}